//
//  UpDateView.m
//  FruitVIP
//
//  Created by 孙艳玲 on 15/6/29.
//  Copyright (c) 2015年 孙艳玲. All rights reserved.
//

#import "UpDateView.h"

#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)

@implementation UpDateView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self getUI];
    }
    return self;
}

- (void)getUI
{
    UILabel *phoneLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, SCREEN_WIDTH/3, 25)];
    phoneLabel.backgroundColor = [UIColor whiteColor];
    phoneLabel.text = @"原始密码";
    [self addSubview:phoneLabel];
    
    self.originalText = [[UITextField alloc] initWithFrame:CGRectMake(phoneLabel.frame.origin.x + phoneLabel.frame.size.width, phoneLabel.frame.origin.y, SCREEN_WIDTH - 20 - phoneLabel.frame.size.width, phoneLabel.frame.size.height)];
    self.originalText.backgroundColor = [UIColor whiteColor];
    self.originalText.secureTextEntry = YES;
    self.originalText.clearsOnInsertion = YES;
    self.originalText.clearButtonMode = UITextFieldViewModeAlways;
    [self addSubview:self.originalText];
    
    UILabel *linePhone = [[UILabel alloc] initWithFrame:CGRectMake(phoneLabel.frame.origin.x, phoneLabel.frame.origin.y + phoneLabel.frame.size.height + 3, SCREEN_WIDTH - 20, 1)];
    linePhone.backgroundColor = [UIColor colorWithRed:230/255.0 green:230/255.0 blue:230/255.0 alpha:1];
    [self addSubview:linePhone];
    
    UILabel *passLabel = [[UILabel alloc] initWithFrame:CGRectMake(phoneLabel.frame.origin.x, linePhone.frame.origin.y + linePhone.frame.size.height + 20, phoneLabel.frame.size.width, phoneLabel.frame.size.height)];
    passLabel.backgroundColor = [UIColor whiteColor];
    passLabel.text = @"重置密码";
    [self addSubview:passLabel];
    
    self.passText = [[UITextField alloc] initWithFrame:CGRectMake(self.originalText.frame.origin.x, passLabel.frame.origin.y, self.originalText.frame.size.width, passLabel.frame.size.height)];
    self.passText.secureTextEntry = YES;//设置密码密文输入
    self.passText.clearsOnInsertion = YES;
    self.passText.clearButtonMode = UITextFieldViewModeAlways;
    [self addSubview:self.passText];
    
    UILabel *passLine = [[UILabel alloc] initWithFrame:CGRectMake(passLabel.frame.origin.x, passLabel.frame.origin.y +passLabel.frame.size.height + 3, SCREEN_WIDTH - 20, 1)];
    passLine.backgroundColor = [UIColor colorWithRed:230/255.0 green:230/255.0 blue:230/255.0 alpha:1];
    [self addSubview:passLine];
    
    UILabel *agianPassLabel = [[UILabel alloc] initWithFrame:CGRectMake(passLabel.frame.origin.x, passLine.frame.origin.y + passLine.frame.size.height + 20, phoneLabel.frame.size.width, phoneLabel.frame.size.height)];
    agianPassLabel.text = @"确认密码";
    agianPassLabel.backgroundColor = [UIColor whiteColor];
    [self addSubview:agianPassLabel];
    
    self.againPassText = [[UITextField alloc] initWithFrame:CGRectMake(agianPassLabel.frame.origin.x + agianPassLabel.frame.size.width , agianPassLabel.frame.origin.y, SCREEN_WIDTH - 20 - agianPassLabel.frame.size.width, agianPassLabel.frame.size.height)];
    self.againPassText.secureTextEntry = YES;
    self.againPassText.clearsOnInsertion = YES;
    self.againPassText.clearButtonMode = UITextFieldViewModeAlways;
    [self addSubview:self.againPassText];
    
    UILabel *againLine = [[UILabel alloc] initWithFrame:CGRectMake(agianPassLabel.frame.origin.x, agianPassLabel.frame.origin.y + agianPassLabel.frame.size.height + 3, SCREEN_WIDTH - 20, 1)];
    againLine.backgroundColor = [UIColor colorWithRed:230/255.0 green:230/255.0 blue:230/255.0 alpha:1];    [self addSubview:agianPassLabel];
    [self addSubview:againLine];
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(SCREEN_WIDTH/4, againLine.frame.origin.y + againLine.frame.size.height + 70, SCREEN_WIDTH/2, SCREEN_WIDTH/8);
     button.layer.cornerRadius = CGRectGetHeight([button bounds])/2;
    [button setTitle:@"确  认" forState:UIControlStateNormal];
    button.backgroundColor = [UIColor colorWithRed:242.0 / 255.0 green:204.0 / 255.0 blue:49.0 / 255.0 alpha:1];
    [button setTitleColor:[UIColor colorWithRed:71.0 / 255.0 green:61.0 / 255.0 blue:55.0 / 255.0 alpha:1] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:button];
    
    self.originalText.delegate = self;
    self.passText.delegate = self;
    self.againPassText.delegate = self;

}


- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.originalText resignFirstResponder];
    [self.passText resignFirstResponder];
    [self.againPassText resignFirstResponder];
    return YES;
}


- (void)buttonAction
{
    [self.myButtonAction buttonAction];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
